package cn.lsngo.manager;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;

/**
 * @Title :
 * @date : 2021/10/27 17:00
 */
public class CommonItemView extends ConstraintLayout {
    private Context mContext;
    private EditText etAirConditionerFeeStart, etAirConditionerFeeEnd;
    private TextView mTvName;
    private String mTitleName;
    private TextView mTvDetail;

    public CommonItemView(@NonNull Context context) {
        super(context);
        this.mContext = context;
    }

    public CommonItemView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        this.mContext = context;
        initAttr(attrs);
        initView();
    }

    private void initAttr(AttributeSet attrs) {
        TypedArray attributes = mContext.obtainStyledAttributes(attrs, R.styleable.CommonItemView);
        mTitleName = attributes.getString(R.styleable.CommonItemView_civ_name);
        attributes.recycle();
    }

    private void initView() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.view_common_item, this, false);
        etAirConditionerFeeStart = (EditText) view.findViewById(R.id.et_air_conditioner_fee_start);
        etAirConditionerFeeEnd = (EditText) view.findViewById(R.id.et_air_conditioner_fee_end);
        mTvName = (TextView) view.findViewById(R.id.tv_name);
        mTvDetail = (TextView) view.findViewById(R.id.txt_detail);
        initData();
        addView(view);
    }

    private void initData() {
        mTvName.setText(mTitleName);
    }

    public String getContentStart() {
        return etAirConditionerFeeStart.getText().toString().trim();
    }

    public String getContentEnd() {
        return etAirConditionerFeeEnd.getText().toString().trim();
    }

    public void setHint(String str) {
        mTvDetail.setText(String.format("需要缴费：%s元", str));
    }

    public void setEndVisible(boolean b) {
        etAirConditionerFeeEnd.setVisibility(b ? VISIBLE : GONE);
    }

    public void setHintContent(String str) {
        etAirConditionerFeeStart.setHint(str);
    }
}
